#include <cstdio>
#include <cstdlib>

using namespace std;

void error(const char* str)
{
    fprintf(stderr, "%s\n", str);
    exit(1);
}

int main(int argc, char** argv)
{
    int N;
    int cost[16][16];
    scanf(" %d", &N);
    if (N <= 1 || N >= 16)
        error("Invalid size.");
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            scanf(" %d", &cost[i][j]);
            if (cost[i][j] < 0)
                error("Invalid cost");
        }
    }
    printf("%d\n", N);
    for (int i = 0; i < N; ++i)
        printf("%d ", N);
    printf("\n");

    for (int r = 1; r < N; ++r) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (j == i) 
                    continue;

                printf("%d", i);
                for (int k = 0; k < r - 1; ++k)
                    printf(" %c", (char)('B' + k));
                printf(" %d", j);

                for (int k = r + 1; k < N; ++k)
                    printf(" -");

                printf(" => ");

                printf("%d", j);
                for (int k = r - 2; k >= 0; --k)
                    printf(" %c", (char)('B' + k));
                printf(" %d", i);
                
                for (int k = r + 1; k < N; ++k)
                    printf(" -");

                printf(" COST %d\n", cost[i][j]);
            }                                     
        }
    }

    printf("GOAL ");
    for (int i = 0; i < N; ++i)
        printf("%d ", i);
    printf("\n");

    printf("\n");

    return 0;
}
